package com.zhumo.sz.controller;


import com.zhumo.sz.common.CommonInsert;
import com.zhumo.sz.common.Result;
import com.zhumo.sz.entity.road.*;
import com.zhumo.sz.service.RoadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.sql.ResultSet;

@Slf4j
@RestController
@RequestMapping("/sz/service/road")
public class RoadController {

    @Autowired
    private RoadService roadService;


    /**
     * 插入成城市公路
     * @param flush
     * @param version
     * @return
     */
    @RequestMapping("/city/add")
    public Result<String> addCityRoad(@RequestParam boolean flush,@RequestParam String version){
        CommonInsert<CityRoad> cityRoadCommonInsert = roadService.addCityRoad(flush, version);
        if (cityRoadCommonInsert.getResult() == cityRoadCommonInsert.getNum()) {
            String message = "插入成功 " + cityRoadCommonInsert.getNum() + "条城市公路信息";
            log.info(message);
            return Result.ok(message);
        }else {
            return Result.fail("插入异常");
        }
    }

    @RequestMapping("/high/add")
    public Result<String> addCityHighSpeedRoad(@RequestParam boolean flush){
        CommonInsert<CityHighRoad> cityRoadCommonInsert = roadService.addCityHeightRoad(flush);
        if (cityRoadCommonInsert.getResult() == cityRoadCommonInsert.getNum()) {
            String message = "插入成功 " + cityRoadCommonInsert.getNum() + "条高速公路信息";
            log.info(message);
            return Result.ok(message);
        }else {
            return Result.fail("插入异常");
        }
    }

    /**
     * 高速公路收费站
     * @param flush
     * @param version
     * @return
     */
    @RequestMapping("/high/addstation")
    public Result<String> addHieghSpeedSatation(@RequestParam boolean flush,@RequestParam String version){
        CommonInsert<HighSpeedTollStation> highSpeedTollStationCommonInsert = roadService.addHighSpeedStations(flush,version);
        if (highSpeedTollStationCommonInsert.getResult() == highSpeedTollStationCommonInsert.getNum()) {
            String message = "插入成功 " + highSpeedTollStationCommonInsert.getNum() + "条高速收费站信息";
            log.info(message);
            return Result.ok(message);
        }else {
            return Result.fail("插入异常");
        }
    }

    @RequestMapping("/high/etc")
    public Result<String> addEtcOrder(@RequestParam boolean flush,@RequestParam String date,@RequestParam String type,@RequestParam int num){
        CommonInsert<CityExpresswayEtcDetail> cityExpresswayEtcDetailCommonInsert = roadService.addEtcOrder(flush,date,type,num);
        if (cityExpresswayEtcDetailCommonInsert.getResult() == cityExpresswayEtcDetailCommonInsert.getNum()) {
            String message = "插入成功 " + cityExpresswayEtcDetailCommonInsert.getNum() + "etc 订单";
            log.info(message);
            return Result.ok(message);
        }else {
            return Result.fail("插入异常");
        }
    }

    /**
     * 测速数据
     * @param flush
     * @param date
     * @param type
     * @param num
     * @return
     */
    @RequestMapping("/road/v")
    public Result<String> addCityRoadV(@RequestParam boolean flush,@RequestParam String date,@RequestParam String type,@RequestParam int num){
        CommonInsert<RoadVelocityDetail> roadVelocityDetailCommonInsert = roadService.addVelocitys(flush,date,type,num);
        if (roadVelocityDetailCommonInsert.getResult() == roadVelocityDetailCommonInsert.getNum()) {
            String message = "插入成功 " + roadVelocityDetailCommonInsert.getNum() + "城市测速数据";
            log.info(message);
            return Result.ok(message);
        }else {
            return Result.fail("插入异常");
        }
    }
}
